package 力扣._6925_故障键盘;

public class Solution {

    StringBuilder reverse(StringBuilder s) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            stringBuilder.insert(0, s.charAt(i));
        }
        return stringBuilder;
    }

    public String finalString(String s) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'i')
                stringBuilder = reverse(stringBuilder);
            else
                stringBuilder.append(s.charAt(i));
        }
        return stringBuilder.toString();
    }
}
